package com.reset.password.controller;

import com.reset.password.entity.User;
import com.reset.password.entity.vo.UserVO;
import com.reset.password.result.Result;
import com.reset.password.service.IUserService;
import com.reset.password.util.EmailUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author pl711@qq.com
 * @PackageName reset-password
 * @Package com.reset.password.controller
 * @Date 2024/11/5 15:56
 * @Version 1.0
 */
@RestController
@Tag(name = "邮箱发送")
@RequestMapping("email")
public class EmailController {
    @Autowired
    private EmailUtil emailUtil;
    @Autowired
    private IUserService userService;
    // 发送邮箱
    @Operation(summary ="")
    @PostMapping("/sendEmail")
    public Result sendEmail(String email){
        Map<String, Object> variables = new HashMap<>();
        UserVO user = userService.findByEmail(email);
        variables.put("user", user.getNickname());
//        variables.put("resetLink", "https://pecel.top/resetYourPassword?email="+user.getEmail());
        variables.put("resetLink", "http://localhost:88?email="+user.getEmail());
        emailUtil.sendMessage(
                email,
                "\uD835\uDD71\uD835\uDD94\uD835\uDD97\uD835\uDD8C\uD835\uDD94\uD835\uDD99 \uD835\uDD95\uD835\uDD86\uD835\uDD98\uD835\uDD98\uD835\uDD9C\uD835\uDD94\uD835\uDD97\uD835\uDD89",
                "reset-your-password",
                variables
        );
        return Result.success();
    }
}
